home *** CD-ROM | disk | FTP | other *** search
/ PC Open 105 / PC Open 105 CD 1.bin / CD1 / INTERNET / COPIA SITI / Getleft / getleft-setup-notcl.exe / {app} / scripts / Herramientas.tcl < prev    next >
Encoding:
Text File  |  2004-03-11  |  27.8 KB  |  778 lines

  1. ###############################################################################
  2. ###############################################################################
  3. ##                        Herramientas.tcl
  4. ###############################################################################
  5. ###############################################################################
  6. ## Includes procedures to implement the commands in the 'Tools' and 'Options'
  7. ## menus.
  8. ###############################################################################
  9. ###############################################################################
  10. ## (c) 1999-2002 AndrΘs Garcφa Garcφa. fandom@retemail.es
  11. ## Distributed under the terms of the GPL v2
  12. ###############################################################################
  13. ###############################################################################
  14.  
  15. namespace eval Herramientas {
  16.  
  17. ###############################################################################
  18. # ExtensionDialog
  19. #    Creates a dialog box to choose file extensions
  20. #
  21. # Parameters:
  22. #    title: title of the dialog box
  23. #    parent: the window over which the dialog will be created.
  24. #    filter: a string with the current filter, defaults to empty.
  25. #
  26. # Side effect:
  27. #    Namespace scope variable 'bot' will contain the choosen extensions
  28. #
  29. # Returns:
  30. #    1: if cancelled
  31. ###############################################################################
  32. proc ExtensionDialog {title parent {filter ""}} {
  33.     global labelButtons labelTitles downOptions indexButtons
  34.     variable done
  35.  
  36.     set coord(x) [winfo rootx $parent]
  37.     set coord(y) [winfo rooty $parent]
  38.  
  39.     set win [toplevel .extDialog]
  40.     wm title $win $title
  41.     wm resizable $win 0 0
  42.     wm geometry $win +[expr {$coord(x)+100}]+[expr {$coord(y)+15}]
  43.  
  44.     set marcoExt [frame $win.marcoext]
  45.     set marcoInt [frame $marcoExt.marcoInt -bd 2 -relief groove]
  46.     set marcoBot [frame $win.marcoBot]
  47.  
  48.     set izqBot1  [checkbutton $marcoInt.bot1  -variable ::Herramientas::bot(1) \
  49.             -onvalue "jpg" -offvalue "" -text "*.jpg"]
  50.     set izqBot2  [checkbutton $marcoInt.bot2  -variable ::Herramientas::bot(2) \
  51.             -onvalue "gif" -offvalue "" -text "*.gif"]
  52.     set izqBot3 [checkbutton  $marcoInt.bot3  -variable ::Herramientas::bot(3) \
  53.             -onvalue "mp3" -offvalue "" -text "*.mp3"]
  54.     set izqBot4  [checkbutton $marcoInt.bot4  -variable ::Herramientas::bot(4) \
  55.             -onvalue "ps"  -offvalue "" -text "*.ps" ]
  56.  
  57.     set cenBot1  [checkbutton $marcoInt.bot5  -variable ::Herramientas::bot(5) \
  58.             -onvalue "pdf" -offvalue "" -text "*.pdf"]
  59.     set cenBot2  [checkbutton $marcoInt.bot6  -variable ::Herramientas::bot(6) \
  60.             -onvalue "txt" -offvalue "" -text "*.txt"]
  61.     set cenBot3  [checkbutton $marcoInt.bot7  -variable ::Herramientas::bot(7) \
  62.             -onvalue "mov" -offvalue "" -text "*.mov"]
  63.     set cenBot4  [checkbutton $marcoInt.bot8  -variable ::Herramientas::bot(8) \
  64.             -onvalue "mpg" -offvalue "" -text "*.mpg"]
  65.  
  66.     set derBot1  [checkbutton $marcoInt.bot9  -variable ::Herramientas::bot(9) \
  67.             -onvalue "avi" -offvalue "" -text "*.avi"]
  68.     set derBot2  [checkbutton $marcoInt.bot10 -variable ::Herramientas::bot(10)\
  69.             -onvalue "zip" -offvalue "" -text "*.zip"]
  70.     set derBot3  [checkbutton $marcoInt.bot11 -variable ::Herramientas::bot(11)\
  71.             -onvalue "tgz" -offvalue "" -text "*.tgz"]
  72.     set derBot4  [checkbutton $marcoInt.bot12 -variable ::Herramientas::bot(12)\
  73.             -onvalue "sit" -offvalue "" -text "*.sit"]
  74.  
  75.  
  76.     if {![string match $title $labelTitles(exclude)]} {
  77.         foreach {index ext} {1 jpg 2 gif 3 mp3 4 ps 5 pdf 6 txt 7 mov 8 mpg 9 avi 10 zip 11 tgz 12 sit} {
  78.             set ::Herramientas::bot($index) $ext
  79.         }
  80.     } else {
  81.         foreach {index ext} {1 jpg 2 gif 3 mp3 4 ps 5 pdf 6 txt 7 mov 8 mpg 9 avi 10 zip 11 tgz 12 sit} {
  82.             if {[regexp "$ext" $filter]} {
  83.                 set ::Herramientas::bot($index) $ext
  84.             } else {
  85.                 set ::Herramientas::bot($index) ""
  86.             }
  87.         }
  88.     }
  89.  
  90.     set aceptar  [underButton::UnderButton $marcoBot.aceptar  -buttontype button\
  91.         -textvariable labelButtons(ok)     -under $indexButtons(ok)             \
  92.         -width 8 -command "set ::Herramientas::done 1"]
  93.     set cancelar [underButton::UnderButton $marcoBot.cancelar -buttontype button\                 \
  94.         -textvariable labelButtons(cancel) -under $indexButtons(cancel)         \
  95.         -width 8 -command "set ::Herramientas::done 0"]
  96.  
  97.     bind $win <Escape> "$cancelar invoke"
  98.  
  99.     pack $marcoExt -ipadx 10 -ipady  5
  100.     pack $marcoInt -ipadx 10 -ipady 15 -side bottom
  101.  
  102.     grid $izqBot1 $cenBot1 $derBot1 -sticky w -padx 3
  103.     grid $izqBot2 $cenBot2 $derBot2 -sticky w -padx 3
  104.     grid $izqBot3 $cenBot3 $derBot3 -sticky w -padx 3
  105.     grid $izqBot4 $cenBot4 $derBot4 -sticky w -padx 3
  106.  
  107.     pack $marcoBot -fill x -padx 7
  108.     pack $cancelar $aceptar  -side right -pady 5 -padx 3
  109.  
  110. #    grab $win
  111.     tkwait variable ::Herramientas::done
  112. #    grab release $win
  113.     destroy $win
  114.     if {$::Herramientas::done==0} {
  115.         return 1
  116.     }
  117.  
  118.     return
  119. }
  120.  
  121. ###############################################################################
  122. # PurgeFilesDir
  123. #    Sweeps a directory turning files to size 0
  124. #
  125. # Parameters:
  126. #    dir: directory to be processed
  127. #    purgarCmd: extensions of the files to minimize
  128. ###############################################################################
  129. proc PurgeFilesDir {dir purgarCmd} {
  130.     global dirGetleft
  131.  
  132.     cd $dir
  133.     set archivos ""
  134.     set extList  [concat $purgarCmd ram jpeg zip aiff]
  135.     foreach ext $extList {
  136.         set archivos [concat $archivos [glob -nocomplain *.$ext]]
  137.         set archivos [concat $archivos [glob -nocomplain [string toupper *.$ext]]]
  138.     }
  139.  
  140.     foreach file $archivos {
  141.         file stat $file estado
  142.         if {$estado(size)!=0} {
  143.             file delete -force $file
  144.             Commands::Touch $file
  145.         }
  146.     }
  147.  
  148.     set directorios [glob -nocomplain */]
  149.  
  150.     foreach dir $directorios {
  151.         update
  152.         PurgeFilesDir $dir $purgarCmd
  153.         cd ..
  154.     }
  155.     return
  156. }
  157.  
  158. ###############################################################################
  159. # PurgeFiles
  160. #    The procedures takes care of recursively clean directories of files
  161. #    with certain extensions *.jpg, *.gif, etc.
  162. ###############################################################################
  163. proc PurgeFiles {} {
  164.     global labelTitles labelMessages dirGetleft
  165.  
  166.     if {[winfo exists .extDialog]} {
  167.         raise .extDialog .
  168.         return
  169.     }
  170.  
  171.     if {[ExtensionDialog $labelTitles(purge) .]==1} {
  172.         return
  173.     }
  174.  
  175.     set dir [Dialogos::SelectDirectory $dirGetleft(toolDir)]
  176.     if {![string compare $dir ""]} {
  177.         return
  178.     }
  179.     set dirGetleft(toolDir) [file dirname $dir]
  180.  
  181.     set dirTmp [pwd]
  182.     for {set i 1;set purgarCmd ""} {$i<13} {incr i} {
  183.         if {$::Herramientas::bot($i)=="tgz"} {
  184.             append purgarCmd tar.gz " "
  185.         } elseif {$::Herramientas::bot($i)=="jpg"} {
  186.             append purgarCmd jpeg   " "
  187.         } elseif {$::Herramientas::bot($i)=="mpg"} {
  188.             append purgarCmd mpeg   " "
  189.         }
  190.         append purgarCmd $::Herramientas::bot($i) " "
  191.     }
  192.     PurgeFilesDir $dir $purgarCmd
  193.  
  194.     tk_messageBox -title $labelTitles(theEnd) -icon info \
  195.         -message $labelMessages(purged)
  196.  
  197.     cd $dirTmp
  198.  
  199.     return
  200. }
  201.  
  202. ###############################################################################
  203. # RestoreOriginalsDir
  204. #    Recursively restores the original files.
  205. #
  206. # Parameter:
  207. #    dir: directory in which it will begin to restore.
  208. ###############################################################################
  209. proc RestoreOriginalsDir {dir} {
  210.  
  211.     cd $dir
  212.     set directorio [glob -nocomplain *.orig]
  213.     foreach fichero $directorio {
  214.         file rename -force -- $fichero [file root $fichero]
  215.     }
  216.  
  217.     set directories [glob -nocomplain */]
  218.     foreach dir $directories {
  219.         RestoreOriginalsDir $dir
  220.         cd ..
  221.     }
  222.     return
  223. }
  224.  
  225. ###############################################################################
  226. # RestoreOriginals
  227. #    Starts the process of restoring the original files downloaded from Web
  228. #    pages.
  229. ###############################################################################
  230. proc RestoreOriginals {} {
  231.     global labelTitles labelMessages dirGetleft
  232.  
  233.     set dir [Dialogos::SelectDirectory $dirGetleft(toolDir)]
  234. #    set dir [tk_chooseDirectory]
  235.     if {![string compare $dir ""]} {
  236.         return
  237.     }
  238.     set dirGetleft(toolDir) [file dirname $dir]
  239.     set dirTmp [pwd]
  240.     RestoreOriginalsDir $dir
  241.  
  242.     tk_messageBox -title $labelTitles(theEnd) -icon info \
  243.             -message $labelMessages(restored)
  244.  
  245.     cd $dirTmp
  246.  
  247.     return
  248. }
  249.  
  250. ###############################################################################
  251. # SameProxy
  252. #    Disables or enables the entries for the ftp proxy, depending on
  253. #    the checkbutton
  254. ###############################################################################
  255. proc SameProxy {} {
  256.     global getleftOptions
  257.     variable ip
  258.  
  259.     for {set i 3} {$i<5} {incr i} {
  260.         if {$getleftOptions(sameProxy)==1} {
  261.             $ip($i) configure -state disabled
  262.             $ip($i) configure -bg $getleftOptions(disBg)
  263.         } else {
  264.             $ip($i) configure -state normal -bg $getleftOptions(bg) \
  265.                     -fg $getleftOptions(fg)
  266.         }
  267.     }
  268.  
  269.     return
  270. }
  271.  
  272. ###############################################################################
  273. # AuthenProxy
  274. #    Disables or enables the entries for authentificatinf proxies.
  275. ###############################################################################
  276. proc AuthenProxy {} {
  277.     global getleftOptions
  278.     variable authen
  279.  
  280.     if {$getleftOptions(useAuthProxy)==1} {
  281.         $authen(name) configure -state normal
  282.         if {$getleftOptions(saveAuthPass)==1} {
  283.             $authen(pass) configure -state normal
  284.         } else {
  285.             $authen(pass) configure -state disabled
  286.         }
  287.         $authen(name) configure -bg $getleftOptions(bg) \
  288.                     -fg $getleftOptions(fg)
  289.         if {$getleftOptions(saveAuthPass)==1} {
  290.             $authen(pass) configure -bg $getleftOptions(bg) \
  291.                     -fg $getleftOptions(fg)
  292.         } else {
  293.             $authen(pass) configure -bg $getleftOptions(disBg)
  294.         }
  295.         $authen(save) configure -state normal
  296.     } else {
  297.         $authen(name) configure -state disabled
  298.         $authen(pass) configure -state disabled
  299.         set getleftOptions(saveAuthPass) 0
  300.         $authen(name) configure -bg $getleftOptions(disBg)
  301.         $authen(pass) configure -bg $getleftOptions(disBg)
  302.         $authen(save) configure -state disabled
  303.     }    
  304.  
  305.     return
  306. }
  307.  
  308. ###############################################################################
  309. # ConfProxyControl
  310. #    Takes the action ordered by the user in the proxy dialog.
  311. #
  312. # Parameter
  313. #    action: 'clear' if the user wants to clear the configuration.
  314. #            'accept' if the user accepts it.
  315. #            'cancel' the user cancels the dialog
  316. #    parent: parent widget of the conf dialog.
  317. #
  318. # Returns:
  319. #    '0' if everything went well and '1' if there was an error.
  320. ###############################################################################
  321. proc ConfProxyControl {action {parent .proxy}} {
  322.     global getleftOptions labelMessages labelTitles
  323.     variable ip
  324.     variable getleftOptionsTemp
  325.     variable authen
  326.  
  327.     switch -exact -- $action {
  328.         clear {
  329.             set getleftOptions(sameProxy) 0
  330.             SameProxy
  331.             for {set i 1} {$i<5} {incr i} {
  332.                 $ip($i) delete 0 end
  333.             }
  334.             catch {unset getleftOptions(httpProxy)}
  335.             catch {unset getleftOptions(ftpProxy)}
  336.             set getleftOptions(proxy) 0
  337.             $authen(name) delete 0 end
  338.             $authen(pass) delete 0 end
  339.             catch {unset getleftOptions(proxyUser)}
  340.             catch {unset getleftOptions(proxyPass)}
  341.             set getleftOptions(useAuthProxy) 0
  342.             set getleftOptions(saveAuthPass) 0
  343.             AuthenProxy
  344.             return 0
  345.         }
  346.         accept {
  347.             for {set i 1} {$i<5} {incr i} {
  348.                 set tmp [$ip($i) get]
  349.                 set dirProxy($i) $tmp
  350.                 if {($getleftOptions(sameProxy)==1)&&($i==2)} break
  351.             }
  352.             if {($dirProxy(1)=="")&&($dirProxy(2)=="")} {
  353.                 catch {unset getleftOptions(httpProxy)}
  354.                 catch {unset getleftOptions(ftpProxy)}
  355.             } else {
  356.                 set getleftOptions(httpProxy)    "$dirProxy(1):$dirProxy(2)"
  357.                 if {$getleftOptions(sameProxy)==0} {
  358.                     set getleftOptions(ftpProxy) "$dirProxy(3):$dirProxy(4)"
  359.                 } else {
  360.                     set getleftOptions(ftpProxy) $getleftOptions(httpProxy)
  361.                 }
  362.                 set getleftOptions(proxy)     1
  363.                 set getleftOptions(proxyUser) [$authen(name) get]
  364.                 set getleftOptions(proxyPass) [$authen(pass) get]
  365.                 if {($getleftOptions(useAuthProxy)==1)\
  366.                     &&($getleftOptions(proxyUser)=="")} {
  367.                     tk_messageBox -type ok -icon error -parent $parent \
  368.                             -message $labelMessages(noUser) -title $labelTitles(error)    
  369.                     return 1
  370.                 }
  371.                 if {($getleftOptions(saveAuthPass)==1) \
  372.                         &&($getleftOptions(proxyPass)=="")} {
  373.                     tk_messageBox -type ok -icon error -parent $parent \
  374.                             -message $labelMessages(noPass) -title $labelTitles(error)
  375.                     return 1
  376.                 }
  377.             }
  378.         }
  379.         cancel {
  380.             array set getleftOptions [array get getleftOptionsTemp]
  381.         }
  382.     }
  383.  
  384.     SaveConfig
  385.     destroy .proxy
  386.  
  387.     return 0
  388. }
  389.  
  390. ###############################################################################
  391. # ConfProxyWindowCommon
  392. #    This procedure takes care of creating the parts of the window that are
  393. #    shared between the proper 'Proxy configure' dialog and the one in the 
  394. #    configuration wizard.
  395. #
  396. # Parameter:
  397. #    The widget in which it will be put.
  398. ###############################################################################
  399. proc ConfProxyWindowCommon {parent} {
  400.     global getleftOptions indexDialogs
  401.     variable ip
  402.     variable authen
  403.  
  404.     set marcoEx   [frame $parent.marcoEx]
  405.     set marcoIn   [frame $marcoEx.marcoIn]
  406.     set marcoIp   [fl::FrameLabel $marcoIn.marcoIp   -bd 2 -relief groove           \
  407.             -textvariable  labelFrames(proxy)]
  408.  
  409.     set label1 [label $marcoIp.label1 -textvariable labelDialogs(http)]
  410.     set ip(1)  [entry $marcoIp.1 -width 20 -bg $getleftOptions(bg)                  \
  411.                     -fg $getleftOptions(fg) -justify  left]
  412.     set ip(2)  [entry $marcoIp.2 -width 4  -bg $getleftOptions(bg)                  \
  413.                     -fg $getleftOptions(fg)]
  414.     set colon1 [label $marcoIp.colon1 -text : -width 2]
  415.  
  416.     set label2 [label $marcoIp.label2  -textvariable labelDialogs(ftp)]
  417.     set ip(3)  [entry $marcoIp.3 -width 20 -bg $getleftOptions(bg)                  \
  418.                     -fg $getleftOptions(fg) -justify  left]
  419.     set ip(4)  [entry $marcoIp.4 -width 4  -bg $getleftOptions(bg)                  \
  420.                     -fg $getleftOptions(fg)]
  421.     set colon2 [label $marcoIp.colon2 -text : -width 2]
  422.  
  423.     set checkIp [underButton::UnderButton $marcoIp.check -buttontype checkbutton    \
  424.             -textvariable labelDialogs(sameProxy) -under $indexDialogs(sameProxy)   \
  425.             -variable getleftOptions(sameProxy) -command ::Herramientas::SameProxy]
  426.  
  427.     set marcoAuth    [fl::FrameLabel $marcoIn.marcoAuth -bd 2 -relief groove        \
  428.             -textvariable labelFrames(authen)]
  429.     set nameLabel    [label $marcoAuth.nameLabel -textvariable labelDialogs(username)]
  430.     set authen(name) [entry $marcoAuth.nameEntry -width 15  -bg $getleftOptions(bg) \
  431.             -fg $getleftOptions(fg)]
  432.     set passLabel    [label $marcoAuth.passLabel -textvariable labelDialogs(password)]
  433.     set authen(pass) [entry $marcoAuth.passEntry -width 15  -bg $getleftOptions(bg) \
  434.             -fg $getleftOptions(fg) -show *]
  435.  
  436.     set authen(use)  [underButton::UnderButton $marcoAuth.use                       \
  437.         -command Herramientas::AuthenProxy -buttontype checkbutton                  \
  438.         -under $indexDialogs(authenUse)                                             \
  439.         -textvariable labelDialogs(authenUse) -variable getleftOptions(useAuthProxy)]
  440.     set authen(save) [underButton::UnderButton $marcoAuth.save                      \
  441.         -under $indexDialogs(authenSave) -buttontype checkbutton                    \
  442.         -command Herramientas::AuthenProxy                                          \
  443.         -textvariable labelDialogs(authenSave) -variable getleftOptions(saveAuthPass)]
  444.  
  445.     grid $marcoEx -padx 7    -ipady 5
  446.     grid $marcoIn -sticky s  -pady 5
  447.     grid $marcoIp $marcoAuth -padx 5 -ipadx 10 -ipady 7 -sticky ns
  448.     grid $label1 -in $marcoIp -row 0 -column 0 -sticky w -pady 3
  449.     grid $ip(1)  -in $marcoIp -row 0 -column 1 -sticky w -pady 3
  450.     grid $colon1 -in $marcoIp -row 0 -column 2 -sticky w -pady 3
  451.     grid $ip(2)  -in $marcoIp -row 0 -column 3 -sticky e -pady 3
  452.     grid $label2 -in $marcoIp -row 1 -column 0 -sticky w -pady 3
  453.     grid $ip(3)  -in $marcoIp -row 1 -column 1 -sticky w -pady 3
  454.     grid $colon2 -in $marcoIp -row 1 -column 2 -sticky w -pady 3
  455.     grid $ip(4)  -in $marcoIp -row 1 -column 3 -sticky e -pady 3
  456.     grid configure $checkIp -columnspan 4
  457.  
  458.     grid $nameLabel    -in $marcoAuth -row 0 -column 0 -padx 5 -pady 3 -sticky w
  459.     grid $authen(name) -in $marcoAuth -row 0 -column 1 -padx 5 -pady 3
  460.     grid $passLabel    -in $marcoAuth -row 1 -column 0 -padx 5 -pady 3 -sticky w
  461.     grid $authen(pass) -in $marcoAuth -row 1 -column 1 -padx 5 -pady 3
  462.     grid $nameLabel    -in $marcoAuth -row 0 -column 0 -padx 5 -pady 3 
  463.     grid configure $authen(use)  -padx 5 -columnspan 2
  464.     grid configure $authen(save) -padx 5 -columnspan 2
  465.  
  466.     focus $ip(1)
  467.     bind $ip(1) <Return>   "focus $ip(2)"
  468.     bind $ip(1) <KP_Enter> "focus $ip(2)"
  469.     bind $ip(2) <Return>   "focus $ip(3)"
  470.     bind $ip(2) <KP_Enter> "focus $ip(3)"
  471.     bind $ip(3) <Return>   "focus $ip(4)"
  472.     bind $ip(3) <KP_Enter> "focus $ip(4)"
  473.     bind $authen(name) <Return>   "focus $authen(pass)"
  474.     bind $authen(name) <KP_Enter> "focus $authen(pass)"
  475.     bind $authen(pass) <Return>   "focus $authen(use)"
  476.     bind $authen(pass) <KP_Enter> "focus $authen(use)"
  477.     bind $authen(use)  <Key-Down> "focus $authen(save)"
  478.     bind $authen(save) <Key-Up>   "focus $authen(use)"
  479.  
  480.     if {[info exists getleftOptions(httpProxy)]} {
  481.         regexp {(.+)(?::)(.+)} $getleftOptions(httpProxy) nada name port
  482.         $ip(1) insert insert $name
  483.         $ip(2) insert insert $port
  484.     }
  485.     if {[info exists getleftOptions(ftpProxy)]} {
  486.         regexp {(.+)(?::)(.+)} $getleftOptions(ftpProxy)  nada name port
  487.         $ip(3)  insert insert $name
  488.         $ip(4)  insert insert $port
  489.     }
  490.     SameProxy
  491.  
  492.     catch {$authen(name) insert insert $getleftOptions(proxyUser)}
  493.     catch {$authen(pass) insert insert $getleftOptions(proxyPass)}
  494.     AuthenProxy
  495.  
  496.     return
  497. }
  498.  
  499. ###############################################################################
  500. # ConfProxyWindow
  501. #    Creates the window in which the user enters his proxy data.
  502. ###############################################################################
  503. proc ConfProxyWindow {} {
  504.     global labelTitles indexButtons
  505.  
  506.     set coord(x) [winfo rootx .]
  507.     set coord(y) [winfo rooty .]
  508.  
  509.     set proxy [toplevel .proxy]
  510.     wm title $proxy $labelTitles(proxy)
  511.     wm resizable $proxy 0 0
  512.     wm geometry  $proxy +[expr {$coord(x)+75}]+[expr {$coord(y)+75}]
  513.  
  514.     ConfProxyWindowCommon $proxy
  515.  
  516.     set botones  [frame  $proxy.marcoEx.botones]
  517.     set clear  [underButton::UnderButton $botones.clear -buttontype button  \
  518.             -textvariable labelButtons(clear)  -under $indexButtons(clear)  \
  519.             -width 8 -command {::Herramientas::ConfProxyControl clear}]
  520.     set accept [underButton::UnderButton $botones.accept -buttontype button \
  521.             -textvariable labelButtons(ok)     -under $indexButtons(ok)     \
  522.             -width 8 -command {::Herramientas::ConfProxyControl accept}]
  523.     set cancel [underButton::UnderButton $botones.cancel -buttontype button \
  524.             -textvariable labelButtons(cancel) -under $indexButtons(cancel) \
  525.             -width 8 -command {::Herramientas::ConfProxyControl cancel}]
  526.  
  527.     bind $proxy <Escape> "$cancel invoke"
  528.  
  529.     grid $botones -sticky e -padx 2
  530.     grid $clear $accept $cancel -padx 3 -sticky n
  531.  
  532.     return
  533. }
  534.  
  535. ###############################################################################
  536. # ConfProxy
  537. #     Allows the user to enter the proxy data
  538. ###############################################################################
  539. proc ConfProxy {} {
  540.     global   getleftOptions
  541.     variable getleftOptionsTemp
  542.  
  543.     if {[winfo exists .proxy]} {
  544.         raise .proxy .
  545.         return
  546.     }
  547.  
  548.     array set getleftOptionsTemp [array get getleftOptions]
  549.     ConfProxyWindow
  550.  
  551.     return
  552. }
  553.  
  554. ###############################################################################
  555. # GetPassControl
  556. #    Takes the action ordered by the user in the 'Get Password' dialog.
  557. ###############################################################################
  558. proc GetPassControl {} {
  559.     global getleftOptions labelMessages
  560.     variable done
  561.     variable authen
  562.  
  563.     set getleftOptions(proxyUser) [$authen(name) get]
  564.     set getleftOptions(proxyPass) [$authen(pass) get]
  565.  
  566.     if {($getleftOptions(proxyPass)=="")} {
  567.         tk_messageBox -type ok -icon error -parent .getPass \
  568.                 -message $labelMessages(noPass)
  569.         return
  570.     }
  571.     SaveConfig
  572.     set done 1
  573.  
  574.     return
  575. }
  576.  
  577. ###############################################################################
  578. # GetPassWindow
  579. #    Dialog to get the Username and password for the proxy.
  580. ###############################################################################
  581. proc GetPassWindow {} {
  582.     global getleftOptions labelButtons labelTitles labelDialogs labelFrames
  583.     variable done
  584.     variable authen
  585.  
  586.     set coord(x) [winfo rootx .]
  587.     set coord(y) [winfo rooty .]
  588.  
  589.     set win [toplevel .getPass]
  590.     wm title $win $labelTitles(proxy)
  591.     wm resizable $win 0 0
  592.     wm geometry  $win +[expr {$coord(x)+125}]+[expr {$coord(y)+75}]
  593.  
  594.     set done 0
  595.  
  596.     set marcoEx    [frame $win.marcoEx]
  597.     set marcoLabel [fl::FrameLabel $marcoEx.marcoIn   -bd 2 -relief groove \
  598.             -textvariable labelFrames(authen)]
  599.     set marcoIn    [frame $marcoLabel.in]
  600.     set nameLabel    [label $marcoIn.nameLabel -textvariable labelDialogs(username)]
  601.     set authen(name) [entry $marcoIn.nameEntry -width 15 -bg $getleftOptions(bg) \
  602.                     -fg $getleftOptions(fg)]
  603.     set passLabel    [label $marcoIn.passLabel -textvariable labelDialogs(password)]
  604.     set authen(pass) [entry $marcoIn.passEntry -width 15 -bg $getleftOptions(bg) \
  605.                     -fg $getleftOptions(fg) -show *]
  606.  
  607.     set authen(save) [checkbutton $marcoIn.save \
  608.         -textvariable labelDialogs(authenSave) -variable getleftOptions(saveAuthPass)]
  609.  
  610.     set botones  [frame  $marcoEx.botones]
  611.     set aceptar  [button $botones.aceptar  -textvariable labelButtons(ok)    \
  612.             -width 8 -command ::Herramientas::GetPassControl]
  613.     set cancelar [button $botones.cancelar -textvariable labelButtons(cancel)\
  614.             -width 8 -command {set ::Herramientas::done 0}]
  615.  
  616.     grid $marcoEx -padx 7   -ipady 5
  617.     grid $marcoLabel -padx 5 -pady 5
  618.     grid $marcoIn -sticky s -pady 10 -padx 5
  619.     grid $nameLabel    -in $marcoIn -row 0 -column 0 -padx 5 -pady 3 -sticky w
  620.     grid $authen(name) -in $marcoIn -row 0 -column 1 -padx 5 -pady 3
  621.     grid $passLabel    -in $marcoIn -row 1 -column 0 -padx 5 -pady 3 -sticky w
  622.     grid $authen(pass) -in $marcoIn -row 1 -column 1 -padx 5 -pady 3
  623.     grid configure $authen(save) -padx 5 -columnspan 2
  624.  
  625.     grid $botones -sticky e -padx 2
  626.     grid $aceptar $cancelar $aceptar -padx 3 -sticky n
  627.  
  628.     bind $win          <Escape>   "$cancelar invoke"
  629.     bind $authen(name) <Return>   "focus $authen(pass)"
  630.     bind $authen(name) <KP_Enter> "focus $authen(pass)"
  631.     bind $authen(pass) <Return>   "focus $authen(save)"
  632.     bind $authen(pass) <KP_Enter> "focus $authen(save)"
  633.     bind $authen(save) <Key-Up>   "focus $authen(save)"
  634.     bind $authen(save) <Key-Down> "focus $aceptar"
  635.  
  636.     if {[catch {$authen(name) insert insert $getleftOptions(proxyUser)}]} {
  637.         focus $authen(name)
  638.     } else {
  639.         focus $authen(pass)
  640.     }
  641.  
  642.     return
  643. }
  644.  
  645. ###############################################################################
  646. # GetPass
  647. #     Queries the user for the password.
  648. #
  649. # Returns
  650. #     '1' if a password is set, '0' otherwise
  651. ###############################################################################
  652. proc GetPass {} {
  653.     global getleftOptions
  654.  
  655.     if {[winfo exists .getPass]} {
  656.         raise .getPass .
  657.         return
  658.     }
  659.  
  660.     array set getleftOptionsTemp [array get getleftOptions]
  661.     GetPassWindow
  662.     tkwait variable ::Herramientas::done
  663.     if {$::Herramientas::done==0} {
  664.         array set getleftOptions [array get getleftOptionsTemp]
  665.     }
  666.  
  667.     destroy .getPass
  668.  
  669.     return $::Herramientas::done
  670. }
  671.  
  672. ###############################################################################
  673. # FilterFiles
  674. #    You can choose which file extensions will be ignored while downloading a
  675. #    Web site.
  676. #
  677. # Parameter:
  678. #    filter: The current filter.
  679. #    parent: The path of the window over which the dialog will be shown,
  680. #            defaults to the main window.
  681. #
  682. # Returns: 
  683. #    A string with the filter, if the users cancells the dialog, it will be
  684. #    the same string passed as a parameter.
  685. ###############################################################################
  686. proc FilterFiles {filter {parent .}} {
  687.     global labelTitles
  688.  
  689.     if {[winfo exists .extDialog]} {
  690.         raise .extDialog .
  691.         return $filter
  692.     }
  693.  
  694.     if {[ExtensionDialog $labelTitles(exclude) $parent $filter]==1} {
  695.         return $filter
  696.     }
  697.     catch {unset urlsDownloaded}
  698.     for {set i 1;set filter ""} {$i<13} {incr i} {
  699.         if {$::Herramientas::bot($i)!=""} {
  700.             if {$::Herramientas::bot($i)=="tgz"} {
  701.                 append filter (tar.gz$) "|"
  702.             } elseif {$::Herramientas::bot($i)=="jpg"} {
  703.                 append filter (jpeg$) "|"
  704.             } elseif {$::Herramientas::bot($i)=="mpg"} {
  705.                 append filter (mpeg$) "|"
  706.             }
  707.             append filter ($::Herramientas::bot($i)$) "|"
  708.         }
  709.     }
  710.     regexp {(.*)(\|)} $filter nada filter
  711.  
  712.     return $filter
  713. }
  714.  
  715. ###############################################################################
  716. # The following is some code I wrote to autodetect a proxy, it works, but it
  717. # sometimes takes hours doing it so I haven't made it available through the GUI
  718. ###############################################################################
  719.  
  720. proc DummyProc {newSock addr port} {
  721.     variable proxyIp
  722.  
  723.     regexp {(.*)(\.)} $addr nada myIp
  724.  
  725.     set proxyIp $myIp.1
  726.  
  727.     return
  728. }
  729.  
  730. proc GuessProxyIp {} {
  731.     variable proxyIp
  732.  
  733.     set serverSocket [socket -server ::Herramientas::DummyProc 11453]
  734.  
  735.     set channel [socket [info hostname] 11453]
  736.  
  737.     tkwait variable ::Herramientas::proxyIp
  738.  
  739.     close $serverSocket
  740.  
  741.     puts "La direccion: $proxyIp"
  742.  
  743.     return
  744. }
  745.  
  746. proc GuessProxyPort {} {
  747.     variable proxyIp
  748.     variable proxyPort
  749.  
  750.     package require http
  751.  
  752.     http::config -proxyhost $proxyIp
  753.     for {set i 80} {$i<=10000} {incr i} {
  754.         http::config -proxyport $i
  755.         if {[catch {http::geturl http://freshmeat.net/} token]} {
  756.             continue
  757.         }
  758.         if {[::http::status $token]=="ok"} {
  759.             regexp {( [0-9][0-9][0-9] )} [::http::code $token] code
  760.             if {$code==200} {
  761.                 set proxyPort $i
  762.                 break
  763.             }
  764.         }
  765.     }
  766.     if {$i<=1000} {
  767.         tk_messageBox -message "El proxy: es $proxyIp:$proxyPort" -type ok -icon info
  768.     } else {
  769.         tk_messageBox -message "No se encontr≤ el proxy" -type ok -icon info
  770.     }
  771.     package forget http
  772.  
  773.     return
  774. }
  775.  
  776. }
  777.  
  778.